<?php
//标签设定
class themesController extends adminController{
    protected $layout = 'layout';
    public function selecttpl(){
        $dirname = $_GET['dir'];
        if($dirname){
            $this->dirpath = $dirname.'/';
            $this->path = explode('/',$dirname);
        }
        $systemdir = model('files')->DirStop($dirname); //读取路径
        $this->frameid = $_GET['id'];
        $this->tpldir = model('files')->SelectDir($systemdir);
        $this->tpllist = model('files')->SelectFile($systemdir,'*.{php}');
        $this->display('themes/selecttpl');  
    } 
    //模板模板列表读取
    public function indextpl(){
        $dirname = $_GET['dir'];
        if($dirname){
            $this->dirpath = $dirname.'/';
            $this->path = explode('/',$dirname);
        }
        $systemdir = model('files')->DirStop($dirname); //读取路径
        $this->tpldir = model('files')->SelectDir($systemdir);
        $this->tpllist = model('files')->SelectFile($systemdir,'*.{php,css,js,txt}');
        $this->display('themes/indextpl');  
    }
    //模版文件编辑
    public function edittpl(){
        $file = new ManageFile(); //文件管理类
        if($this->isPost()){
            $files = $_POST['files'];
            $content = $_POST['content'];
            $filepath = $_POST['filepath'];
            $dirpath  = model('files')->DirStop($filepath);
            $rel = $file->write_file($dirpath,$content);
            if($rel){
                $this->pageMsg('模板修改成功',1,url('themes/edittpl',array('dir'=>$filepath,'files'=>$files)));
            }else{
                $this->pageMsg('模板修改失败,请确认模板目录权限是否777');
            }
        }else{
            $this->filepath = $_GET['dir'];
            $this->files = $_GET['files'];
            if($this->filepath){
                $this->path = explode('/', $this->filepath);
            }
            $this->dirpath  = model('files')->DirStop($this->filepath,0,1);
            if(!$this->dirpath){
                $this->pageMsg('模板读取失败,请确认模板是否存在',0,url('themes/indextpl'));
            }
            $this->filecontents = $file -> contents_file($this->dirpath);
            $this->display('themes/edittpl');    
        }
    }
}